<template>
	<div class="store-room">
    <div class="table-title">
      <el-button type="primary" @click="handleAdd" data-auth="store_category_add">添加房型</el-button>
	    <el-button type="primary" @click="zoneAdd" data-auth="store_category_floor">设置楼层</el-button>
    </div>
    <div class="table-content">
      <el-table
        border
        :data="tableData"
        @expand-change="openData"
        :expand-row-keys="openKey"
        :row-key="getKey"
        style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-table
              :data="tableColData"
              border
              style="width: 100%">
              <el-table-column
                label="政策类型"
                prop="PolicyTypeDes">
              </el-table-column>
              <el-table-column
                label="政策名称"
                prop="PolicyName">
              </el-table-column>
              <el-table-column label="操作" width="250px">
                <template slot-scope="scope">
	                 <el-button
	                    size="mini"
	                    @click="handleColEdit(scope.$index, scope.row)" data-auth="store_category_modifypolicy">编辑</el-button>
                  <el-button
                    size="mini"
                    type="danger"
                    @click="handleColDelete(scope.$index, scope.row)" data-auth="store_category_deletepolicy">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column
          label="房型"
          prop="Name">
        </el-table-column>
        <el-table-column
          label="简称"
          prop="ShortName">
        </el-table-column>
        <el-table-column
          label="房间数">
					<template slot-scope="scope">
						{{scope.row.RoomList.length}}
          </template>
        </el-table-column>
        <el-table-column
          label="房间号">
					<template slot-scope="scope">
						<template v-for="(m,index) in scope.row.RoomList">
							{{m.RoomNo}}
							<template v-if="index<scope.row.RoomList.length-1">
								,
							</template>
						</template>
          </template>
        </el-table-column>
        <el-table-column
          label="床型"
          prop="BedTypeDesc">
        </el-table-column>
        <el-table-column label="操作" width="250px">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)" data-auth="store_category_modify">编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)" data-auth="store_category_delete">删除</el-button>
						<el-button
							size="mini"
							type="primary"
							@click="handleColPrice(scope.$index, scope.row)" data-auth="store_category_addpolicy">添加政策</el-button>
						<el-button
							size="mini"
							type="primary"
							style="margin-top:10px;margin-left:0"
							@click="initroominventorybatch(scope.$index, scope.row)" data-auth="store_category_inventory">手动生成库存</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="table-page">

    </div>
    <el-dialog
      :title="dialogTitle"
      :visible.sync="roomShow"
      width="550px"
      center>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px">
        <el-form-item label="房型名称：" prop="Name">
          <el-input v-model="ruleForm.Name"></el-input>
        </el-form-item>
        <el-form-item label="房型简称：" prop="ShortName">
          <el-input v-model="ruleForm.ShortName"></el-input>
        </el-form-item>
        <el-form-item label="床型：" prop="BedTypeDesc">
          <el-input v-model="ruleForm.BedTypeDesc"></el-input>
        </el-form-item>
        <el-form-item label="房间面积：" prop="RoomArea">
          <el-input v-model="ruleForm.RoomArea"></el-input>
        </el-form-item>
        <el-form-item label="最多可住人数：" prop="MaxCapacity">
          <el-input v-model="ruleForm.MaxCapacity"></el-input>
        </el-form-item>
        <el-form-item label="所在楼层：" prop="FloorDesc">
          <el-input v-model="ruleForm.FloorDesc"></el-input>
        </el-form-item>
        <el-form-item label="是否有窗户：" prop="HasWindow">
          <el-radio-group v-model="ruleForm.HasWindow">
            <el-radio label="true">是</el-radio>
            <el-radio label="false">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否可吸烟：" prop="CanSmoke">
          <el-radio-group v-model="ruleForm.CanSmoke">
            <el-radio label="true">是</el-radio>
            <el-radio label="false">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否可上网：" prop="NetDevice">
          <el-radio-group v-model="ruleForm.NetDevice">
            <el-radio label="true">是</el-radio>
            <el-radio label="false">否</el-radio>
          </el-radio-group>
        </el-form-item>
				<el-form-item label="房型图片：" prop="ImageList">
					<el-upload
            class="avatar-uploader"
            action="/"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload"
            >
            <el-button type="primary">点击上传房型图片</el-button>
          </el-upload>
          <div class="el-upload__tip">请上传png、jpg及jpeg格式图片(大小2M以下,建议分辨率256*256)</div>
          <span class="upload-imglist" v-for="(m,index) in ruleForm.ImageList">
            <el-checkbox v-model="m.IsMaster" label="设置为封面图" @change="setIsMasterPhoto(m)"></el-checkbox>
            <img v-if="ruleForm.ImageList.length>0" :src="m.Url">
            <i class="el-icon-circle-close-outline" @click="ruleForm.ImageList.splice(index,1)"></i>
          </span>
        </el-form-item>
        <el-form-item label=" 房间号：" prop="RoomList" class="roomNo-row">
					<span v-for="(m,index) in ruleForm.RoomList">
						<el-input v-model="m.RoomNo"></el-input>
						<i class="el-icon-circle-close-outline" @click="deleteRoom(m,index)"></i>
					</span>
        </el-form-item>
				<div class="addRoom" @click="ruleForm.RoomList.push({RoomNo:''})">添加房间号</div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="roomAddEdit('ruleForm')">{{dialogTitle==='添加房型'?'确认添加':'确认修改'}}</el-button>
        <el-button @click="roomShow = false">取 消</el-button>
      </span>
    </el-dialog>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="roomColShow"
      width="750px"
      center>
			<div class="floor">
				<div class="floor-title">
					楼层设置
				</div>
				<div class="floor-main">
		        <div v-if="!!floorList.length" class="floor-form" v-for="element in floorList" :key="element.Id">
		            {{element.ZoneName}}-{{element.FloorName}}楼
								<span class="el-icon-delete" @click="deleteFloor(element.Id)"></span>
		        </div>
						<div v-if="!floorList.length">
								请添加楼层
						</div>
				</div>
				<div class="floor-add">
					<el-select v-model="colForm.ZoneId" placeholder="请选择" style="width:160px">
						<el-option
							v-for="m in zoneList"
							:label="m.Name"
							:value="m.Id"
							:key="m.Id">
						</el-option>
					</el-select>
					<el-input v-model="colForm.FloorNo" placeholder="楼层" style="width:100px"></el-input>
					<el-button @click="addFloor" :disabled="!colForm.ZoneId||!colForm.FloorNo" style="width:100px">添加楼层</el-button>
				</div>

				<div class="floor-insert">
					<div class="insert-main" style="margin:0;color:#333;background:#ccc;font-size:16px;height:40px;">
						<div class="insert-left">
								楼层
						</div>
						<div class="insert-right">
							 房间
						</div>
					</div>
					<div class="insert-main"  style="margin:0;">
						<div class="insert-left">
								未设置楼层
						</div>
						<draggable v-model="UnSetBelongRoomList" :options="{group:'floor'}" class="insert-right">
				        <div class="floor-form" v-for="element in UnSetBelongRoomList" :key="element.Id">
				            {{element.RoomNo}}
				        </div>
						</draggable>
					</div>
					<div class="insert-main">
						<div class="insert-left">
								批量移动
						</div>
						<div class="insert-right" style="padding:15px;">
							<el-select v-model="setBelongList" multiple filterable placeholder="请选择房号" style="width:50%">
								 <el-option
									 v-for="m in UnSetBelongRoomList"
									 :label="m.RoomNo"
									 :value="m.Id"
									 :key="m.Id">
								 </el-option>
							 </el-select>
							 <el-select v-model="ZoneId" placeholder="请选择" style="width:29%">
		 						<el-option
		 							v-for="m in floorList"
		 							:label="m.ZoneName+'-'+m.FloorName+'楼'"
		 							:value="m.Id"
		 							:key="m.Id">
		 						</el-option>
		 					</el-select>
	 						<el-button @click="moveFloor" :disabled="!setBelongList.length||!ZoneId" style="width:100px">移动楼层</el-button>
						</div>
					</div>
					<div v-for="m in floorList" :key="m.Id" class="insert-main">
						<div class="insert-left">
								{{m.ZoneName}}-{{m.FloorName}}楼
						</div>
						<draggable v-model="m.RoomList" :options="{group:'floor'}" class="insert-right">
				        <div class="floor-form" v-for="element in m.RoomList" :key="element.Id">
				            {{element.RoomNo}}
				        </div>
						</draggable>
					</div>
				</div>
			</div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveFloorRoom" :disabled="floorList.every(val=>{return !val.RoomList.length})">设置楼层</el-button>
        <el-button @click="roomColShow = false">取 消</el-button>
      </span>
    </el-dialog>

		<el-dialog
      :title="'手动生成库存'"
      :visible.sync="initShow"
      width="550px"
      center>
      <el-form label-width="100px">
        <el-form-item label="生成日期：">
					<el-date-picker
						v-model="initdateTime"
						type="daterange"
						:editable="false"
						range-separator="至"
						start-placeholder="开始日期"
						end-placeholder="结束日期"
						:picker-options="pickerOptions"
					>
					</el-date-picker>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" :disabled="!initdateTime.length" @click="initdateTrue">生成</el-button>
      </span>
    </el-dialog>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="priceShow"
      width="750px"
      class="price-model"
      center>
      <el-form :model="priceForm" ref="priceForm" label-width="140px">
        <div class="price-title">设置统一价格</div>
				<div style="width:100%;">
					<el-form-item label="政策名称：" label-width="160px" prop="PolicyConfigId" :rules="{ required: true, message: '请选择政策',type:'number',trigger: 'change' }">
						<el-select v-model="priceForm.PolicyConfigId" :disabled="dialogTitle==='编辑政策'" placeholder="请选择政策">
	            <el-option v-for="m in PolicyConfigList" :label="m.Name" :value="m.Id" :key="m.Id"></el-option>
	          </el-select>
          </el-form-item>
					<el-form-item label="统一价格日期：" label-width="160px" prop="dateTime" :rules="{ required: true, message: '请选择日期', trigger: 'change' }">
						<el-date-picker
							v-model="priceForm.dateTime"
							type="daterange"
							:editable="false"
							range-separator="至"
							start-placeholder="开始日期"
							end-placeholder="结束日期"
							:picker-options="pickerOptions"
						>
						</el-date-picker>
          </el-form-item>
				</div>
        <div class="month-price">
					<template v-for="(m,index) in priceForm.WeekPriceList">
						<el-form-item :label="m.dayName" :prop="'WeekPriceList.' + index + '.Price'" :rules="{ required: true, message: '价格不能为空', trigger: 'blur' }	">
	            <el-input v-model="m.Price"></el-input>
	          </el-form-item>
					</template>
        </div>
        <div class="price-title">设置特殊价格</div>
        <div class="spcial-price">
          <div class="btn" @click="priceForm.SpecialPriceList.push({dateTime:[],Price:''})">
            <i class="el-icon-plus"></i>
            <span icon="el-icon-plus">新增特殊价格</span>
          </div>
          <div class="spcial-form" v-for="(m,index) in priceForm.SpecialPriceList">
            <el-form-item label-width="0" :prop="'SpecialPriceList.' + index + '.dateTime'" :rules="{ required: true, message: '请选择日期', trigger: 'change' }">
              <el-date-picker
                v-model="m.dateTime"
                type="daterange"
								:editable="false"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
								:picker-options="SpecialpickerOptions">
              </el-date-picker>
            </el-form-item>
            <el-form-item label-width="0" :prop="'SpecialPriceList.' + index + '.Price'" :rules="{ required: true, message: '价格不能为空', trigger: 'blur' }	">
              <el-input width="150px" v-model="m.Price" placeholder="特殊价格"></el-input>
            </el-form-item>
            <div class="btn" @click="priceForm.SpecialPriceList.splice(index,1)">
              <i class="el-icon-minus"></i>
              <span icon="el-icon-plus">删除本条价格</span>
            </div>
          </div>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addPrice('priceForm')">保存</el-button>
        <el-button @click="priceShow = false">取 消</el-button>
      </span>
    </el-dialog>


	</div>
</template>
<script>
import draggable from 'vuedraggable'
	  export default {
				components: {
            draggable,
        },
        data () {
						var roomRule = (rule, value, callback) => {
							if (value.every((val)=>{return !val.RoomNo})) {
								callback(new Error('请至少输入一个房间号'));
							} else {
							 	callback();
							}
					 	};
						var priceRule = (rule, value, callback) => {
							callback();
					 	};
						let _this=this;
            return {
							initdateTime:[],
							SpecialpickerOptions: {
			          disabledDate(time) {
									let start=(time.getTime() + 3600 * 1000 * 24 * 1)< Date.now();
									if(!_this.priceForm.dateTime){
										return start
									}else{
										let end=new Date(_this.priceForm.dateTime[1]).getTime() + 3600 * 1000 * 24 * 1;
										start=time.getTime()<new Date(_this.priceForm.dateTime[0]).getTime()
										return start||time>=end
									}
			          }
			        },
							pickerOptions: {
			          disabledDate(time) {
			            // return (time.getTime() + 3600 * 1000 * 24 * 1)< Date.now();
			          }
			        },
              dialogTitle:'',
              roomShow:false,
              roomColShow:false,
              priceShow:false,
							initShow:false,
              openKey:[],
							dateTime:'',
              tableData: [],
							tableColData:[],
							PolicyConfigList:[],
              ruleForm: {
								HotelId:JSON.parse(sessionStorage.getItem('nowmenu')).Id,
							  ImageList: [],
							  Name: "",
							  ShortName: "",
							  BedTypeDesc: "",
							  RoomArea: "",
							  MaxCapacity: "",
							  FloorDesc: "",
							  HasWindow: true,
							  CanSmoke:true,
							  NetDevice: true,
							  RoomList: [{RoomNo:''}]
              },
              colForm: {
								ZoneId:'',
                FloorNo: '',
              },
              priceForm:{
								dateTime:'',
	              SpecialPriceList:[],
								WeekPriceList:[
									{DayOfWeek:0,dayName:'周一',Price:''},
									{DayOfWeek:1,dayName:'周二',Price:''},
									{DayOfWeek:2,dayName:'周三',Price:''},
									{DayOfWeek:3,dayName:'周四',Price:''},
									{DayOfWeek:4,dayName:'周五',Price:''},
									{DayOfWeek:5,dayName:'周六',Price:''},
									{DayOfWeek:6,dayName:'周日',Price:''}
								]
              },
              rules: {
                Name: [
                  { required: true, message: '请输入房型名称', trigger: 'blur' },
                ],
                ShortName: [
                  { required: true, message: '请选择房型简称', trigger: 'blur' }
                ],
                BedTypeDesc: [
                  { required: true, message: '请输入床型', trigger: 'blur' },
                ],
                RoomArea: [
                  { required: true, message: '请输入房间面积', trigger: 'blur' },
                ],
                MaxCapacity: [
                  { required: true, message: '请输入最多可住人数', trigger: 'blur' }
                ],
								FloorDesc: [
                  { required: true, message: '请输入所在楼层', trigger: 'blur' }
                ],
								HasWindow: [
                  { required: true, message: '请选择是否有窗', trigger: 'change' }
                ],
								CanSmoke: [
                  { required: true, message: '请选择是否可吸烟', trigger: 'change' }
                ],
								NetDevice: [
                  { required: true, message: '请选择是否可上网', trigger: 'change' }
                ],
								RoomList: [
                  { required: true,validator: roomRule, trigger: 'blur' }
                ],
								ImageList: [
                  { required: true,validator: (rule, value, callback) => {
                      if (!_this.ruleForm.ImageList.length) {
                        callback(new Error('请上传酒店图片'));
                      } else {
                        callback();
                      }
                    }, trigger: 'focus' }
                ],
              },
							zoneList:[],
							floorList:[],
							checkZoneList:[],
							UnSetBelongRoomList:[],
							setBelongList:[],
							ZoneId:''
            }
        },
        created(){
					this.getList();
					this.GetConfigList();
					this.$ajax.GetHotelZoneList().then(res=>{
						if(res.Success){
							this.zoneList=res.Data;
						}
					})
        },
        methods:{
					beforeAvatarUpload(file) {
		        const isJPG = file.type === 'image/jpeg'||file.type === 'image/png';
		        const isLt2M = file.size / 1024 / 1024 < 2;
		        if (!isJPG) {
		          this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
		          return
		        }
		        if (!isLt2M) {
		          this.$message.error('上传头像图片大小不能超过 2MB!');
		          return
		        }
		        let reader = new FileReader()
		        reader.readAsDataURL(file)
		        reader.onloadend = ()=>{
		          file.url = reader.result;
		          this.$ajax.upLoadImg({FileName:file.name,FileBase64:file.url.split(',')[1]}).then(res=>{
		            if(res.Success){
		                this.ruleForm.ImageList.push(
		                  {
		                    Name: file.name,
		                    Url: res.Data,
		                    IsMaster: false
		                  }
		                );
										this.$refs['ruleForm'].validateField('ImageList');
		            }
		          })
		        }
		        return false;
		      },
					setIsMasterPhoto(m){
		        _.map(this.ruleForm.ImageList,val=>{
		          if(val.Name!==m.Name){
		            val.IsMaster=false;
		          }
		        })
		      },
					initList(){
						this.roomShow=false;
						this.roomColShow=false;
						this.priceShow=false;
						this.getList();
					},
					getList(){
						this.$ajax.GetRoomCategoryList({hotelId:this.ruleForm.HotelId}).then(res=>{
							if(res.Success&&res.Data){
								this.tableData=res.Data;
							}
						})
					},
					GetConfigList(){
						this.$ajax.GetConfigList().then(res=>{
							if(res.Success&&res.Data){
								this.PolicyConfigList=res.Data;
							}
						})
					},
          getKey(row){
            return row.Id;
          },
          resetForm(formName) {
            if(!this.$refs[formName]){return};
            this.$refs[formName].resetFields();
          },
					gettableColData(id){
						this.$ajax.getpolicylist({roomCategoryId:id}).then(res=>{
							if(res.Success&&res.Data){
								this.tableColData=res.Data;
							}
						})
					},
          openData(row, expandedRows){
						if(this.openKey[0]===row.Id){
							this.openKey=[]
						}else{
							this.openKey=[row.Id]
							this.gettableColData(row.Id);
						}
          },
          handleAdd(index, row) {
            this.dialogTitle='添加房型';
            this.resetForm('ruleForm');
						this.ruleForm={
							HotelId:JSON.parse(sessionStorage.getItem('nowmenu')).Id,
							Name: "",
							ShortName: "",
							BedTypeDesc: "",
							RoomArea: "",
							MaxCapacity: "",
							FloorDesc: "",
							HasWindow: "true",
							CanSmoke:"true",
							NetDevice: "true",
							ImageList: [],
							RoomList: [{RoomNo:''}]
						};
            this.roomShow=true;
          },
          handleEdit(index, row) {
            this.dialogTitle='编辑房型';
            this.resetForm('ruleForm');
						this.$ajax.GetRoomCategory({id:row.Id}).then(res=>{
							if(res.Success){
								let data=res.Data;
								this.ruleForm=data;
								this.ruleForm.ImageList=this.ruleForm.ImageList||[];
		            this.roomShow=true;
							}
						})
          },
          handleDelete(index, row) {
            this.deleteShow('确认删除此房型?',row.Id,'DeleteRoomCategory')
          },
					GetHotelZoneFloorList(){
						this.colForm={
							ZoneId:'',
							FloorNo: '',
						}
						this.setBelongList=[];
						this.ZoneId='';
						this.$ajax.GetRoomBelongZoneFloor().then(res=>{
							if(res.Success&&res.Data){
								this.floorList=res.Data.Data.ZoneFloorList;
								this.UnSetBelongRoomList=res.Data.Data.UnSetBelongRoomList;
							}
						})
					},
					zoneAdd(){
						this.GetHotelZoneFloorList();
            this.dialogTitle='设置楼层';
						this.roomColShow=true;
					},
          handleColEdit(index, row) {
						console.log(row)
            this.dialogTitle='编辑政策';
						this.priceForm={
							Id:row.Id,
							RoomCategoryId:row.RoomCategoryId,
							PolicyConfigId:row.PolicyConfigId,
							dateTime:[row.StartDate,row.EndDate],
							SpecialPriceList:[],
							WeekPriceList:[
								{DayOfWeek:0,dayName:'周一',Price:row.MondayPrice},
								{DayOfWeek:1,dayName:'周二',Price:row.TuesdayPrice},
								{DayOfWeek:2,dayName:'周三',Price:row.WednesdayPrice},
								{DayOfWeek:3,dayName:'周四',Price:row.ThursdayPrice},
								{DayOfWeek:4,dayName:'周五',Price:row.FridayPrice},
								{DayOfWeek:5,dayName:'周六',Price:row.SaturdayPrice},
								{DayOfWeek:6,dayName:'周日',Price:row.SundayPrice}
							]
						};
						this.resetForm('priceForm');
            this.priceShow=true;
          },
          handleColDelete(index, row) {
            console.log(index, row);
            this.deleteShow('确认删除此政策?',row,'deletepolicy')
          },
          deleteShow(title,id,api){
            this.$confirm(title, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
              center: true
            }).then(() => {
							let data={
								id:api==='deletepolicy'?id.Id:id
							};
							this.$ajax[api](data).then(res=>{
								if(res.Success){
									this.$message({
					          showClose: true,
		                type: 'success',
		                message: '已删除!'
		              });
									this.initList();
									if(api==='deletepolicy'){this.gettableColData(id.RoomCategoryId);}
								}
							})
            }).catch(() => {
            });
          },
          handleColPrice(index, row){
						this.dialogTitle='添加政策';
						this.priceForm={
							RoomCategoryId:row.Id,
							PolicyConfigId:'',
							dateTime:'',
							SpecialPriceList:[],
							WeekPriceList:[
								{DayOfWeek:0,dayName:'周一',Price:''},
								{DayOfWeek:1,dayName:'周二',Price:''},
								{DayOfWeek:2,dayName:'周三',Price:''},
								{DayOfWeek:3,dayName:'周四',Price:''},
								{DayOfWeek:4,dayName:'周五',Price:''},
								{DayOfWeek:5,dayName:'周六',Price:''},
								{DayOfWeek:6,dayName:'周日',Price:''}
							]
						};
						this.resetForm('priceForm');
            this.priceShow=true;
          },
					initroominventorybatch(index,row){
						this.roomCategoryId=row.Id;
						this.initdateTime=[];
						this.initShow=true;
					},
					initdateTrue(){
						let data={
							roomCategoryId:this.roomCategoryId,
							startDate:this.initdateTime[0],
							endDate:this.initdateTime[1],
						}
						this.$ajax.initroominventorybatch(data).then(res=>{
							if(res.Success){
								this.$message.success('生成成功!');
								this.initShow=false;
								this.getList();
							}
						})
					},
					deleteRoom(m,index){
						if(this.dialogTitle==='添加房型'||!m.Id){
							this.ruleForm.RoomList.splice(index,1)
						}else{
							this.$ajax.deleteroom({id:m.Id}).then(res=>{
								if(res.Success){
									this.ruleForm.RoomList.splice(index,1);
									this.getList();
								}
							})
						}
					},
					roomAddEdit(formName){
						this.$refs[formName].validate((valid) => {
              if (valid) {
								let data=_.cloneDeep(this.ruleForm);
                this.$ajax.SaveRoomCategory(data).then(res=>{
									if(res.Success){
										this.$message.success(this.dialogTitle+'成功!');
										this.$refs[formName].resetFields();
										this.initList();
									}
                })
              } else {
                return false;
              }
            });
					},
					addPrice(formName){
						this.$refs[formName].validate((valid) => {
              if (valid) {
								let data={
									RoomCategoryId:this.priceForm.RoomCategoryId,
									PolicyConfigId:this.priceForm.PolicyConfigId,
									MondayPrice:this.priceForm.WeekPriceList[0].Price,
									TuesdayPrice:this.priceForm.WeekPriceList[1].Price,
									WednesdayPrice:this.priceForm.WeekPriceList[2].Price,
									ThursdayPrice:this.priceForm.WeekPriceList[3].Price,
									FridayPrice:this.priceForm.WeekPriceList[4].Price,
									SaturdayPrice:this.priceForm.WeekPriceList[5].Price,
									SundayPrice:this.priceForm.WeekPriceList[6].Price,
									StartDate:this.$format('yyyy-MM-dd',this.priceForm.dateTime[0]),
									EndDate:this.$format('yyyy-MM-dd',this.priceForm.dateTime[1]),
									SpecialPriceList:this.priceForm.SpecialPriceList
								};
								_.map(data.SpecialPriceList,(val)=>{
									val.StartDate=this.$format('yyyy-MM-dd',val.dateTime[0]);
									val.EndDate=this.$format('yyyy-MM-dd',val.dateTime[1]);
								})
								if(this.dialogTitle==='编辑政策'){
									data.Id=this.priceForm.Id
								}
								this.$nextTick(()=>{
									console.log(data)
	                this.$ajax.savepolicy(data).then(res=>{
										if(res.Success){
											this.$message.success(this.dialogTitle+'成功!');
											this.$refs[formName].resetFields();
											this.initList();
											if(this.openKey.length>0){this.gettableColData(this.openKey[0]);}
										}
	                })
								})
              } else {
                return false;
              }
            });
					},
					addFloor(){
						this.$ajax.AddZoneFloor(this.colForm).then(res=>{
							if(res.Success){
								this.$message.success('已添加!');
								this.GetHotelZoneFloorList();
							}
						})
					},
					deleteFloor(id){
						this.$ajax.DeleteZoneFloor({id:id}).then(res=>{
							if(res.Success){
								this.$message({
				          showClose: true,
									type: 'success',
									message: '已删除!'
								});
								this.GetHotelZoneFloorList();
							}
						})
					},
					moveFloor(){
						let data=[];
						this.setBelongList.forEach(val=>{
							this.UnSetBelongRoomList.forEach((value,index)=>{
								if(val===value.Id){
									data.push({
										Id:value.Id,
										RoomNo:value.RoomNo,
										ZoneFloorId:this.ZoneId,
									});
									this.UnSetBelongRoomList.splice(index,1);
								}
							})
						})
						this.floorList.forEach(val=>{
							if(val.Id===this.ZoneId){
								val.RoomList.push(...data);
							}
						})
						this.setBelongList=[];
						this.ZoneId='';
					},
					saveFloorRoom(){
						let data={
							FloorList:[{Id:0,RoomList:this.UnSetBelongRoomList},...this.floorList]
						}
						this.$ajax.SaveRoomZoneFloorBelong(data).then(res=>{
							if(res.Success){
								this.$message.success('设置成功!');
								this.initList();
							}
						})
					}
        }
	  }
</script>
<style lang="scss">
.floor{
	.floor-title{
		font-size: 16px;
		margin-bottom: 10px;
	}
	.floor-add{
		margin: 20px 0;
	}
	.floor-main,.floor-insert{
		border-bottom: 1px dotted #dadada;
		div.floor-form{
			display: inline-block;
			min-width: 77px;
    	text-align: center;
			padding: 5px 10px;
			border: 1px solid #dadada;
			margin:5px 10px 10px 0;
			border-radius: 10px;
			cursor: pointer;
			.el-icon-delete{
				margin-left:5px;
				&:hover{
					color:#f56c6c
				}
			}
			&:hover{
				color:#66b1ff;
				border-color: #66b1ff;
			}
		}
	}
	.floor-insert{
		div.floor-form{
			cursor: move;
		}
	}
	.floor-insert{
		.insert-main{
			display: table;
			width: 100%;
			border-collapse: collapse;
	    border: 1px dotted #dadada;
	    margin-bottom: 20px;
			min-height: 50px;
		}
		.insert-left,.insert-right{
			display: table-cell;
			min-width: 130px;
			vertical-align: middle;
			padding:0 15px;
		}
		.insert-left{
			width: 20%;
			border-left: 1px dotted #dadada;
			white-space: nowrap;
		}
	}
}
</style>
